package map_set.map;

import java.io.BufferedReader;
import java.io.FileReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    private static void test1() {
        TreeMap<String, Integer> tm = new TreeMap<>();
        tm.put("a", 1);
        tm.put("b", 2);
        tm.put("c", 3);
        tm.put("c", 7);
        tm.put("d", 4);
        tm.put("e", 5);
        int c = tm.getOrDefault("ca", 0);
        System.out.println(c);
        Set<String> ks = tm.keySet();
        for (String k : ks) {
            System.out.print(k + " ");
        }
        System.out.println();
        Set<Map.Entry<String, Integer>> es = tm.entrySet();
        for (Map.Entry<String, Integer> e : es) {
            System.out.print(e.getKey() + "=" + e.getValue() + " ");
        }
        System.out.println();
    }

    private static void test2() {
        TreeSet<String> ts = new TreeSet<>();
        ts.add("a");
        ts.add("b");
        ts.add("c");
        ts.add("c");
        ts.add("d");
        ts.add("e");
        for (String s : ts) {
            System.out.print(s + " ");
        }
        System.out.println();
        Iterator<String> it1 = ts.iterator();
        while (it1.hasNext()) {
            System.out.print(it1.next() + " ");
        }
        System.out.println();
    }

    /**
     * 统计一个java源代码文件中，单词出现的频率
     */
    private static void test3() {
        HashMap<String, Integer> hm = new HashMap<>();
        try (BufferedReader br = new BufferedReader(
                new FileReader(
                        "D:\\桌面\\code\\bit\\bit_work_Java\\data_struct\\src\\sort\\Sort.java"))) {
            String line;
            String regex = "\\b\\w+\\b";
            Pattern p = Pattern.compile(regex);
            while ((line = br.readLine()) != null) {
                Matcher m = p.matcher(line);
                while (m.find()) {
                    String s = m.group();
                    hm.put(s, hm.getOrDefault(s, 0) + 1);
                }
            }
            for (String s : hm.keySet()) {
                System.out.println(s + "=" + hm.get(s));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void func(String str1, String str2) {
        str1 = str1.toUpperCase();
        str2 = str2.toUpperCase();
        System.out.println("str1=" + str1);
        System.out.println("str2=" + str2);

        HashSet<Character> set = new HashSet<>();

        for (Character ch : str2.toCharArray()) {
            set.add(ch);
        }

        for (Character ch : str1.toCharArray()) {
            if (!set.contains(ch)) {
                System.out.print(ch);
                set.add(ch);
            }
        }
    }


    private static void test4() {
        func("7_This_is_a_test", "_hs_s_a_es");
    }

    public static void main(String[] args) {
//        test1();
//        test2();
//        test3();
        test4();
    }
}
